﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharedGenomics.Workbench.Core
{
    public class AuthenticatedWebServiceProxyFactory : WebServiceProxyFactory
    {
        public AuthenticatedWebServiceProxyFactory(ILoginRequiredGuard loginGuard, IWebServiceEndpointRegistry endpointRegistry)
            : base(endpointRegistry)
        {
            this.LoginGuard = loginGuard;
        }

        public override T CreateProxy<T>()
        {
            T proxy = default(T);

            this.LoginGuard.Guard((uc) =>
            {
                proxy = base.CreateProxy<T>();
                uc.ApplyToWebServiceProxy(proxy);
            });

            return proxy;
        }

        private ILoginRequiredGuard LoginGuard { get; set; }
    }
}
